package base2

var (
	ApiResponseEntityErrorCode   = -1
	ApiResponseEntitySuccessCode = 200
)

type ApiResponseEntity[T any] struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

func (m ApiResponseEntity[T]) IsSuccess() bool {
	if m.Code >= 0 {
		return true
	}
	return false
}

func (m ApiResponseEntity[T]) IsError() bool {
	if m.Code < 0 {
		return true
	}
	return false
}

func NewErrorApiResponseEntity[T any](msg string) ApiResponseEntity[T] {
	var t T
	return NewApiResponseEntity[T](ApiResponseEntityErrorCode, msg, t)
}
func NewErrorApiResponseEntity2[T any](code int, msg string, data T) ApiResponseEntity[T] {
	return NewApiResponseEntity(code, msg, data)
}

func NewSuccessApiResponseEntity[T any](data T) ApiResponseEntity[T] {
	return NewApiResponseEntity(ApiResponseEntitySuccessCode, "", data)
}

func NewApiResponseEntity[T any](code int, msg string, data T) ApiResponseEntity[T] {
	return ApiResponseEntity[T]{Code: code, Msg: msg, Data: data}
}

type ApiPagerResponse[T any] struct {
	List      []T
	PageTotal int64 `example:"1000"`
}

type ApiPagerRequest struct {
	PageIndex int `example:"1"`
	PageSize  int `example:"20"`
}
